<template>
	<div class="loginbg">
      <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="demo-ruleForm login-container">
        <div class="login-title">
          <img src="../assets/login_title.png" alt="">
        </div>
        <h3 class="title">商户登录入口</h3>
        <el-form-item prop="account" style="text-align: center;position: relative;">
<!--          <el-input type="text" v-model="ruleForm2.account" auto-complete="off" placeholder="请输入账号"></el-input>-->
          <span style="position: absolute;left: 12px;top: 0;font-size: 30px;color: #b5b1b5"><i class="fa fa-user"></i></span>
          <input type="text" v-model="ruleForm2.account" auto-complete="off" placeholder="请输入账号" class="user"@keyup.enter="handleSubmit2">
        </el-form-item>
        <el-form-item prop="checkPass" style="text-align: center;position: relative;">
<!--          <el-input type="password" v-model="ruleForm2.checkPass" auto-complete="off" placeholder="请输入密码"></el-input>-->
          <span style="position: absolute;left: 12px;top: 0;font-size: 30px;color: #b5b1b5"><i class="fa fa-lock"></i></span>
          <input type="password" v-model="ruleForm2.checkPass" auto-complete="off" placeholder="请输入密码" class="user" @keyup.enter="handleSubmit2">
        </el-form-item>
<!--        <el-checkbox v-model="checked" checked class="remember">记住密码</el-checkbox>-->
        <el-form-item style="text-align: center;">
          <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining" class="btn">登录</el-button>
          <!--<el-button @click.native.prevent="handleReset2">重置</el-button>-->
<!--          <div class="tip">如果忘记密码，请联系管理员</div>-->
        </el-form-item>
        <el-form-item style="width:100%;">
          <div class="tip">如果忘记密码，请联系管理员</div>
        </el-form-item>
      </el-form>
	</div>
</template>

<script>
  import { getUserList,login } from '../api/userAPI'
  import { requestLogin } from '../api/api';
  //import NProgress from 'nprogress'
  export default {
    data() {
      return {
        userList: [], // 用户列表
        logining: false,
        ruleForm2: {
          account: 'admin',
          checkPass: 'admin'
        },
        rules2: {
          account: [
            { required: true, message: '请输入账号', trigger: 'blur' },
            //{ validator: validaePass }
          ],
          checkPass: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            //{ validator: validaePass2 }
          ]
        },
        checked: true
      };
    },
    methods: {
      handleReset2() {
        this.$refs.ruleForm2.resetFields();
      },
      handleSubmit2(ev) {
        var _this = this;
        this.$refs.ruleForm2.validate((valid) => {
          if (valid) {
            //_this.$router.replace('/table');
            this.logining = true;
            //NProgress.start();
            let user = { username: this.ruleForm2.account, password: this.ruleForm2.checkPass };
            login(user).then(res => {
                if (res.code === 20002) {
                    this.$message({
                      message: res.message,
                      type: 'error'
                    });
                    this.logining = false;
                    return false
                } else if (res.code === 0) {
                      this.$message({
                        message: '登入成功',
                        type: 'success'
                      });
                      this.logining = false;
                      console.log(res.data.user)
                      // sessionStorage.setItem('user', JSON.stringify(user));
                      sessionStorage.setItem('user', JSON.stringify(res.data.user));
                      this.$router.push({ path: '/Allinfo' });
                }
            }).catch(err => {
              this.logining = false;
              // this.$message({
              //   message: err.response.data.message,
              //   type: 'error'
              // })
            })

            // let user = { username: this.ruleForm2.account, password: this.ruleForm2.checkPass };
            // sessionStorage.setItem('user', JSON.stringify(user));
            // this.$router.push({ path: '/Allinfo' });
          } else {
                console.log('error submit!!');
                return false;
          }
        });
      }
    },
    created() {
        // 获取所有的用户列表
        // getUserList().then(res => {
        //   console.log(res.data.user)
        //   this.userList = res.data.user
        // })
    }
  }

</script>

<style lang="scss" scoped>
	.loginbg{
		/*background: #f9f9f9;*/
      background: url("../assets/login_bg.jpg") no-repeat fixed center center;
      background-size: cover;
      height: 100%;
      width: 100%;
      position: relative;
	}
  .login-container {
    /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
    -webkit-border-radius: 5px;
    border-radius: 20px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    width: 350px;
    padding: 35px 35px 15px;
    background: #fff;
    opacity: 0.9;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    position: fixed;
    top:50%;
    left: 50%;
    transform: translate(-50%,-70%);
    .login-title {
      width: 152px;
      height: 26px;
      margin: 0 auto;
      img {
        width: 100%;
      }
    }
    .title {
      margin: 22px auto 40px auto;
      text-align: center;
      /*color: #505458;*/
      font-size: 20px;
      color: #9b70a5;
    }
    .remember {
      margin: 0 0 35px 0;
    }
    .btn {
      background-color: #e94e80;
      border-radius: 18px;
      border-color: #e94e80;
      font-size: 12px;
      color: #fff;
    }
    .tip {
      text-align: center;
      font-size: 10px;
      line-height: 2px;
      color: #b5b1b5;
    }
    .user {
      width: 88%;
      height: 39px;
      border: none;
      outline: none;
      padding-left: 45px;
    }
  }
</style>
